package kr.go.nih.biomedi.snptorrent.servlet;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.go.nih.biomedi.snptorrent.bo.Cytoband;
import kr.go.nih.biomedi.snptorrent.dao.CytobandDao;

public class CytobandServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public CytobandServlet() {
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String chrom = request.getParameter("chrom"); 
		
		int width = 800;
		int height = 50;
		CytobandDao cytoband = new CytobandDao();
		BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = image.createGraphics();
		
		g.setColor(Color.BLACK);

		
		try {
			List<Cytoband> list = (List<Cytoband>) cytoband.getCytoBandChromosomeName(chrom);
			for (int i = 0; i < list.size(); i++) {
				Cytoband cyto = (Cytoband) list.get(i);
				System.out.println(cyto.getChromStart());
			}
			g.drawRect(10, 10, 60, 20);
		} catch (SQLException se) {
			System.out.println("no Search");
		} 
		
		
		ServletOutputStream outStream = response.getOutputStream();
		ImageIO.write(image, "png", outStream);
		outStream.close();
	}
}
 